import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';

class Device {
  ///获取设备信息
  static get deviceInfo async {
    final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
    Map<String, dynamic> deviceData = <String, dynamic>{};
    AndroidDeviceInfo? androidInfo;
    IosDeviceInfo? iosInfo;
    if (Platform.isIOS) {
      iosInfo = await deviceInfoPlugin.iosInfo;
    } else {
      androidInfo = await deviceInfoPlugin.androidInfo;
    }
    deviceData = _readDeviceInfo(androidInfo, iosInfo);
    return deviceData;
  }

//result:{deviceBrand: iPhone, deviceSysVersion: 13.1, deviceType: iOS, deviceModel: Tock, deviceIMEI: 3C54652C-29D7-4E1B-BFCA-B94C204533E9}
//result:{deviceBrand: HUAWEI , deviceSysVersion: 10, deviceType: Android, deviceModel: HMA-AL00, deviceIMEI: 1bc8ac61fd63b479}
  static _readDeviceInfo(
      AndroidDeviceInfo? androidInfo, IosDeviceInfo? iosInfo) {
    Map<String, dynamic> data = <String, dynamic>{
      //手机品牌
      "deviceBrand": Platform.isIOS ? iosInfo?.model : androidInfo?.brand,
      //当前系统版本
      "sysVersion": Platform.isIOS
          ? iosInfo?.systemVersion
          : androidInfo?.version.release,
      //设备类型
      "deviceType": Platform.isIOS ? "iOS" : "Android",
      //手机具体的固件型号/Ui版本
      "deviceModel": Platform.isIOS ? iosInfo?.name : androidInfo?.model,
      //手机设备的用户唯一识别码
      "deviceMei": Platform.isIOS
          ? iosInfo?.identifierForVendor
          : androidInfo?.androidId,
    };
    return data;
  }
}
